﻿

function DialogSearch_OnClick()
{  
    try
    {
        if ($("#txtCODE1").val() == "" && $("#txtCODE2").val() == "")
		{
            if (Number($("#txtCODE1").val()) > Number($("#txtCODE2").val()))
			{
                $("#lblCODE_ERR").text(GetMessageByID("MSG017").text);
			}
			else
			{
                $("#lblCODE_ERR").text("");
			}
		}
		else
		{
            if ($("#txtCODE1").val() == "")
			{
                $("#txtCODE1").val($("#txtCODE2").val());
			}
            else if ($("#txtCODE2").val() == '')
			{
                $("#txtCODE2").val($("#txtCODE1").val());
			}
		}
		
		
		
        if ($("#txtDEPT_DATE1").val() == "" || $("#txtDEPT_DATE2").val() == "")
		{
            $("#lblDEPT_DATE_ERR").text(GetMessageByID("MSG019").text);
		}
		else
		{
			
            var sYYYYMM = $("#txtDEPT_DATE1").val();
			//var eYYYYMM=document.all.txtDEPT_DATE2.value.substr(0,4);
			var ServerDate=getServerInfoByClient("date");
			//var now_date= ServerDate.substr(0,4);
			var sdate=DateAdd1('d',180,ServerDate);
			//alert(sdate);
			
			if(sYYYYMM<sdate)
			{
			    $("#lblDEPT_DATE_ERR").text(GetMessageByID("MSG059").text);
			}
			else
			{
			    if (isNaN($("#txtDEPT_DATE1").val()) || isNaN($("#txtDEPT_DATE2").val()))
				{
			        $("#lblDEPT_DATE_ERR").text(GetMessageByID("MSG021").text);
				}
				else
				{
			        if (Number($("#txtDEPT_DATE1").val()) >Number( $("#txtDEPT_DATE2").val()))
					{
			            $("#lblDEPT_DATE_ERR").text(GetMessageByID("MSG017").text);
					}
					else
					{
			            $("#lblDEPT_DATE_ERR").text("");
			            if (CACL_DATE($("#txtDEPT_DATE2").val(), $("#txtDEPT_DATE1").val()) > 100)
						{
			                $("#lblDEPT_DATE_ERR").text(GetMessageByID("MSG018").text);
						}
					}
				}
				
			}
		}
		
        if ($("#lblDEPT_DATE_ERR").text() == "" && $("#lblCODE_ERR").text() == "")
		{
			return true;
		}
		else
		{
		alert(GetMessageByID("MSG020").text)
			return false;
		}
		
    }
	catch (e)
	{
        alert(e.Message);
        return false;
	}
	finally
	{
	
	}
}


function DateAdd1(timeU,byMany,oDate1)
{
	try
	{
		oYear1=oDate1.substr(0,4);
		oMonth1=oDate1.substr(4,2)-1;
		oDay1=oDate1.substr(6,2);
		
		var millisecond=1;
		var second=millisecond*1000;
		var minute=second*60;
		var hour=minute*60;
		var day=hour*24;
		var year=day*365;

		var newDate;
		var dVal=new Date(oYear1,oMonth1,oDay1);
		switch(timeU) {
			case "ms": newDate=new Date(dVal+millisecond*byMany); break;
			case "s": newDate=new Date(dVal+second*byMany); break;
			case "mi": newDate=new Date(dVal+minute*byMany); break;
			case "h": newDate=new Date(dVal+hour*byMany); break;
			case "d": newDate=new Date(dVal-day*byMany); break;
			case "y": newDate=new Date(dVal+year*byMany); break;
		}
		var oYear=newDate.getYear();
		var oMonth=newDate.getMonth()+1;
		var oDate=newDate.getDate();
		if (parseInt(oMonth) < 10)
		{
			oMonth="0" + oMonth;
		} 
		
		if (parseInt(oDate) < 10)
		{
			oDate="0" + oDate;
		} 
		
		
		var oYMD=String(oYear) + String(oMonth) + String(oDate);
		return oYMD;
	} 
	catch(e)
	{
		ShowError(e.message);
	}
}

function printReport()
{
	var url = "../ReportViewer.aspx?ReportName=\\VND\\Report\\VNDR020R.rpt" + 
			  "&Param0=" + document.getElementById('hidVENDOR').value + 
			  "&Param1=" + document.getElementById('txtDEPT_DATE1').value + 
			  "&Param2=" + document.getElementById('txtDEPT_DATE2').value + 
			  "&Param3=" + document.getElementById('txtCODE1').value + 
			  "&Param4=" + document.getElementById('txtCODE2').value ;
			 // "&Param5=" + document.getElementById('txtDEPT_DATE2').value.substr(0,6) ; //P3511M0179-B2B平台廠商使用銷售庫存量線上查詢,開放報表給前台列印

	
	window.open(url, "PRINT", "width=850, height=610, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
}
